<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
<title>日程安排</title>
<%@ include file="/common/header/meta.jsp"%>
<%@ include file="/common/header/script.jsp"%>

<script src="/easy/script/plugins/dhtmlxScheduler_v4.1.0/codebase/dhtmlxscheduler.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="/easy/script/plugins/dhtmlxScheduler_v4.1.0/codebase/dhtmlxscheduler.css" type="text/css" media="screen" title="no title">
<script src="/easy/script/plugins/dhtmlxScheduler_v4.1.0/codebase/locale/locale_cn.js" type="text/javascript" charset="utf-8"></script>
<script src="/easy/script/plugins/dhtmlxScheduler_v4.1.0/codebase/ext/dhtmlxscheduler_year_view.js" type="text/javascript" charset="utf-8"></script>
<script src="/easy/script/plugins/dhtmlxScheduler_v4.1.0/codebase/ext/dhtmlxscheduler_multisource.js" type="text/javascript" charset="utf-8"></script>


<script type="text/javascript">
$(function() {
	scheduler.config.xml_date="%Y-%m-%d %H:%i";
	scheduler.config.limit_time_select = true;
	scheduler.init('scheduler_here',new Date(),"day");
	
	scheduler.load(base.contextPath+"/sysmgr/schedule/doNotNeedAuth_schedules.do?mode=day&start_date="+new Date().format("yyyy-MM-dd"),"json");
	
	//点击保存按钮前触发
	scheduler.attachEvent("onEventSave", function(event_id,event_object) {
		if (!event_object.text) {
			alert("请填写你的日程信息在保存！"); return false;
		}
		return true;
	}) ;
	
	//添加事件，点击保存按钮后触发
	scheduler.attachEvent("onEventAdded", function(event_id,event_object) {
		sumbitNow(base.contextPath+"/sysmgr/schedule/doNotNeedAuth_add.do", event_id, event_object) ;
	}) ;
	
	//编辑事件，点击保存后触发
	scheduler.attachEvent("onEventChanged", function(event_id,event_object) {
		if (!event_object.text) {
			alert("请填写你的日程信息在保存！"); return false;
		} else {
			sumbitNow(base.contextPath+"/sysmgr/schedule/doNotNeedAuth_edit.do", event_id, event_object) ;
		}
	}) ;
	
	
	//点击删除按钮后触发
	scheduler.attachEvent("onEventDeleted", function(event_id,event_object) {
		sumbitNow(base.contextPath+"/sysmgr/schedule/doNotNeedAuth_delete.do", event_id, event_object) ;
	}) ;
	
	
	//视图切换触发
	scheduler.attachEvent("onViewChange", function(new_mode, new_date) {
		$.ajax({
	        url: base.contextPath+"/sysmgr/schedule/doNotNeedAuth_schedules.do", type: "post", dataType: "json",
	        data: {mode: new_mode, start_date: new Date(new_date).format("yyyy-MM-dd")},
	        beforeSend: function (XMLHttpRequest) {  },
	        success: function (result, textStatus, XMLHttpRequest) {
	        	scheduler.clearAll();
	        	scheduler.parse(result,"json");
	        },
	        complete: function (XMLHttpRequest,textStatus) {},
	        error: function(XMLHttpRequest, textStatus, errorThrown) {
	        	alertify.success("发生错误！");
	        }
	    });
		
	}) ;
});

function sumbitNow(url, event_id, event_object) {
	var sdatestr=new Date(event_object.start_date).format("yyyy-MM-dd HH:mm:ss");  
    var edatestr=new Date(event_object.end_date).format("yyyy-MM-dd HH:mm:ss");  
    var data = {"id":event_id,"start_date":sdatestr,"end_date":edatestr,"text":event_object.text,"user_id":base.user_id} ;
    console.dir(data);
    $.ajax({
        url: url, type: "post", dataType: "json", data: data,
        beforeSend: function (XMLHttpRequest) { },
        success: function (result, textStatus, XMLHttpRequest) {
        	if (result.status) {
				alertify.success(result.msg);
			} else {
				alertify.error(result.msg);
			}
        },
        complete: function (XMLHttpRequest,textStatus) {},
        error: function(XMLHttpRequest, textStatus, errorThrown) {
        	alertify.success("发生错误！");
        }
    }); 
}
</script>
</head>

<body>
	<div id="scheduler_here" class="dhx_cal_container" style='width:100%; height:100%;'>
		<div class="dhx_cal_navline">
			<div class="dhx_cal_prev_button">&nbsp;</div>
			<div class="dhx_cal_next_button">&nbsp;</div>
			<div class="dhx_cal_today_button"></div>
			<div class="dhx_cal_date"></div>
			<div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div>
			<div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div>
			<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div>
			<div class="dhx_cal_tab" name="year_tab" style="right:140px;"></div>
		</div>
		<div class="dhx_cal_header">
		</div>
		<div class="dhx_cal_data">
		</div>
	</div>	
</body>
</html>